package lc_1330_翻转子数组得到最大的数组值;

public class Solution {

	public int maxValueAfterReverse(int[] nums) {
		int n = nums.length;
		int base = 0, diff = 0;
		int mx = Integer.MIN_VALUE, mn = Integer.MAX_VALUE;
		for (int i = 0; i < n - 1; i++) {
			int a = nums[i], b = nums[i + 1];
			mx = Math.max(mx, Math.min(a, b));
			mn = Math.min(mn, Math.max(a, b));
			base += Math.abs(a - b);
			diff = Math.max(diff,
					Math.max(Math.abs(b - nums[0]) - Math.abs(a - b), Math.abs(a - nums[n - 1]) - Math.abs(a - b)));
		}
		return base + Math.max(diff, 2 * (mx - mn));
	}

}
